/*
 * SPDX-License-Identifier: MIT
 * SPDX-FileCopyrightText: Copyright (c) 2021 Jason Skuby (mytechtoybox.com)
 */

#ifndef PICO_BOARD_CONFIG_H_
#define PICO_BOARD_CONFIG_H_

#include "enums.pb.h"
#include "class/hid/hid.h"

#define BOARD_CONFIG_LABEL "MiSTercade V2"

#define DEFAULT_INPUT_MODE INPUT_MODE_GENERIC
#define DEFAULT_DPAD_MODE DPAD_MODE_DIGITAL

// Main pin mapping Configuration
//                                                  // GP2040 | Xinput | Switch  | PS3/4/5  | Dinput | Arcade |
#define GPIO_PIN_02 GpioAction::BUTTON_PRESS_UP     // UP     | UP     | UP      | UP       | UP     | UP     |
#define GPIO_PIN_03 GpioAction::BUTTON_PRESS_DOWN   // DOWN   | DOWN   | DOWN    | DOWN     | DOWN   | DOWN   |
#define GPIO_PIN_04 GpioAction::BUTTON_PRESS_RIGHT  // RIGHT  | RIGHT  | RIGHT   | RIGHT    | RIGHT  | RIGHT  |
#define GPIO_PIN_05 GpioAction::BUTTON_PRESS_LEFT   // LEFT   | LEFT   | LEFT    | LEFT     | LEFT   | LEFT   |
#define GPIO_PIN_13 GpioAction::BUTTON_PRESS_B1     // B1     | A      | B       | Cross    | 2      | K1     |
#define GPIO_PIN_06 GpioAction::BUTTON_PRESS_B2     // B2     | B      | A       | Circle   | 3      | K2     |
#define GPIO_PIN_07 GpioAction::BUTTON_PRESS_R2     // R2     | RT     | ZR      | R2       | 8      | K3     |
#define GPIO_PIN_09 GpioAction::BUTTON_PRESS_L2     // L2     | LT     | ZL      | L2       | 7      | K4     |
#define GPIO_PIN_10 GpioAction::BUTTON_PRESS_B3     // B3     | X      | Y       | Square   | 1      | P1     |
#define GPIO_PIN_11 GpioAction::BUTTON_PRESS_B4     // B4     | Y      | X       | Triangle | 4      | P2     |
#define GPIO_PIN_12 GpioAction::BUTTON_PRESS_R1     // R1     | RB     | R       | R1       | 6      | P3     |
#define GPIO_PIN_08 GpioAction::BUTTON_PRESS_L1     // L1     | LB     | L       | L1       | 5      | P4     |
#define GPIO_PIN_16 GpioAction::BUTTON_PRESS_S1     // S1     | Back   | Minus   | Select   | 9      | Coin   |
#define GPIO_PIN_17 GpioAction::BUTTON_PRESS_S2     // S2     | Start  | Plus    | Start    | 10     | Start  |
#define GPIO_PIN_14 GpioAction::BUTTON_PRESS_L3     // L3     | LS     | LS      | L3       | 11     | LS     |
#define GPIO_PIN_15 GpioAction::BUTTON_PRESS_R3     // R3     | RS     | RS      | R3       | 12     | RS     |
#define GPIO_PIN_18 GpioAction::BUTTON_PRESS_E1     // Twin Stick Up
#define GPIO_PIN_19 GpioAction::BUTTON_PRESS_E2     // Twin Stick Down
#define GPIO_PIN_20 GpioAction::BUTTON_PRESS_E3     // Twin Stick Left
#define GPIO_PIN_21 GpioAction::BUTTON_PRESS_E4     // Twin Stick Right
#define GPIO_PIN_22 GpioAction::BUTTON_PRESS_E4     // Player 2 Start


// Keyboard Mapping Configuration
//                                            // GP2040 | Xinput | Switch  | PS3/4/5  | Dinput | Arcade |
#define KEY_DPAD_UP     HID_KEY_ARROW_UP      // UP     | UP     | UP      | UP       | UP     | UP     |
#define KEY_DPAD_DOWN   HID_KEY_ARROW_DOWN    // DOWN   | DOWN   | DOWN    | DOWN     | DOWN   | DOWN   | 
#define KEY_DPAD_RIGHT  HID_KEY_ARROW_RIGHT   // RIGHT  | RIGHT  | RIGHT   | RIGHT    | RIGHT  | RIGHT  | 
#define KEY_DPAD_LEFT   HID_KEY_ARROW_LEFT    // LEFT   | LEFT   | LEFT    | LEFT     | LEFT   | LEFT   | 
#define KEY_BUTTON_B1   HID_KEY_SHIFT_LEFT    // B1     | A      | B       | Cross    | 2      | K1     |
#define KEY_BUTTON_B2   HID_KEY_Z             // B2     | B      | A       | Circle   | 3      | K2     |
#define KEY_BUTTON_R2   HID_KEY_X             // R2     | RT     | ZR      | R2       | 8      | K3     |
#define KEY_BUTTON_L2   HID_KEY_V             // L2     | LT     | ZL      | L2       | 7      | K4     |
#define KEY_BUTTON_B3   HID_KEY_CONTROL_LEFT  // B3     | X      | Y       | Square   | 1      | P1     |
#define KEY_BUTTON_B4   HID_KEY_ALT_LEFT      // B4     | Y      | X       | Triangle | 4      | P2     |
#define KEY_BUTTON_R1   HID_KEY_SPACE         // R1     | RB     | R       | R1       | 6      | P3     |
#define KEY_BUTTON_L1   HID_KEY_C             // L1     | LB     | L       | L1       | 5      | P4     |
#define KEY_BUTTON_S1   HID_KEY_5             // S1     | Back   | Minus   | Select   | 9      | Coin   |
#define KEY_BUTTON_S2   HID_KEY_1             // S2     | Start  | Plus    | Start    | 10     | Start  |
#define KEY_BUTTON_L3   HID_KEY_EQUAL         // L3     | LS     | LS      | L3       | 11     | LS     |
#define KEY_BUTTON_R3   HID_KEY_MINUS         // R3     | RS     | RS      | R3       | 12     | RS     |
#define KEY_BUTTON_A1   HID_KEY_9             // A1     | Guide  | Home    | PS       | 13     | ~      |
#define KEY_BUTTON_A2   HID_KEY_F2            // A2     | ~      | Capture | ~        | 14     | ~      |
#define KEY_BUTTON_FN   -1                    // Hotkey Function                                        |

#define BOARD_LEDS_PIN 28 // Addressible RGB LED for buttons

#define LED_BRIGHTNESS_MAXIMUM 150
#define LED_BRIGHTNESS_STEPS 5
#define LED_FORMAT LED_FORMAT_GRB
#define LEDS_PER_PIXEL 1

#define LEDS_DPAD_LEFT   11
#define LEDS_DPAD_DOWN   10
#define LEDS_DPAD_RIGHT  9
#define LEDS_DPAD_UP     0
#define LEDS_BUTTON_B3   8
#define LEDS_BUTTON_B4   7
#define LEDS_BUTTON_R1   6
#define LEDS_BUTTON_L1   5
#define LEDS_BUTTON_B1   1
#define LEDS_BUTTON_B2   2
#define LEDS_BUTTON_R2   3
#define LEDS_BUTTON_L2   4
#define LEDS_BUTTON_S1   -1
#define LEDS_BUTTON_S2   -1
#define LEDS_BUTTON_L3   -1
#define LEDS_BUTTON_R3   -1
#define LEDS_BUTTON_A1   -1
#define LEDS_BUTTON_A2   -1

#define HAS_I2C_DISPLAY 1
#define I2C_SDA_PIN 0
#define I2C_SCL_PIN 1
#define I2C_BLOCK i2c0
#define I2C_SPEED 400000
#define DISPLAY_FLIP 0
#define DISPLAY_INVERT 0

#define DEFAULT_SPLASH \
0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00, \
0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xE9,0xFF,0xFF,0x93,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8, \
0x20,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x04, \
0x40,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x07,0xF0,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x03,0xCF,0xF9,0xE0,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x03,0x3F,0xFE,0x40,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x0E,0x00,0xFF,0xFF,0x80,0x70,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x1F,0xC1,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x01,0xFB,0xFF,0xFF,0xEF,0x80,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0xFB,0xFF,0xFF,0xEF,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x73,0xFF,0xFF,0xF6,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x04,0x3F,0xFF,0x30,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x0B,0xDF,0xFE,0xD8,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x0B,0x6F,0xFD,0xA8,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x0B,0x2F,0xFD,0x28,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x05,0xAB,0xFD,0x68,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x06,0xDB,0xFD,0xD8,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x03,0x3D,0xFE,0x30,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x03,0xFD,0xF7,0xE0,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x01,0xFD,0xEF,0xC0,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0xFD,0xEF,0x80,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x7D,0xEF,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x7B,0xEF,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF7,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xEF,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x7A,0xD6,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0xCE,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x02, \
0x40,0x60,0x18,0xC1,0xC1,0xFE,0x7E,0x3F,0x30,0x01,0xE0,0x0C,0x0F,0xE0,0x7F,0x82, \
0x40,0x60,0x18,0xC7,0xF1,0xFE,0x7F,0x1F,0xE4,0x03,0xF8,0x0C,0x0F,0xF0,0x7F,0x82, \
0x40,0x70,0x38,0xCC,0x38,0x30,0x60,0x00,0xCE,0x06,0x18,0x1C,0x0C,0x18,0x40,0x02, \
0x40,0x70,0x38,0xCC,0x08,0x30,0x60,0x1F,0x83,0x0C,0x00,0x16,0x0C,0x0C,0x40,0x02, \
0x40,0x58,0x68,0xCC,0x00,0x30,0x60,0x1F,0x03,0x18,0x00,0x36,0x0C,0x06,0x40,0x02, \
0x40,0x58,0x68,0xC7,0x00,0x30,0x60,0x0E,0x03,0x18,0x00,0x32,0x0C,0x06,0x40,0x02, \
0x40,0x4C,0xCC,0xC3,0xE0,0x30,0x7F,0x0C,0x86,0x10,0x00,0x63,0x0C,0x06,0x7F,0x02, \
0x40,0xCC,0xCC,0xC0,0x70,0x30,0x7F,0x19,0xFC,0x10,0x00,0x63,0x0C,0x06,0x7F,0x02, \
0x40,0xC4,0x8C,0xC0,0x18,0x30,0x60,0x11,0x8C,0x18,0x00,0x41,0x8C,0x06,0x40,0x02, \
0x40,0xC7,0x8C,0xC0,0x18,0x30,0x60,0x01,0x8C,0x1C,0x00,0xFF,0x8C,0x04,0x40,0x02, \
0x20,0xC3,0x0C,0xC8,0x18,0x30,0x60,0x01,0x86,0x0E,0x18,0xC0,0x8C,0x0C,0x40,0x04, \
0x1E,0xC3,0x0C,0xCE,0x30,0x30,0x7F,0xC3,0x87,0x07,0xF9,0x80,0xCF,0xF8,0x7F,0xB8, \
0x00,0xC3,0x0C,0xC7,0xE0,0x30,0x7F,0xC3,0x83,0x83,0xF1,0x80,0xCF,0xF0,0x7F,0x80

#define BUTTON_LAYOUT BUTTON_LAYOUT_STICK
#define BUTTON_LAYOUT_RIGHT BUTTON_LAYOUT_STICKLESSB
#define SPLASH_MODE SPLASH_MODE_STATIC
#define SPLASH_CHOICE SPLASH_CHOICE_MAIN
#define SPLASH_DURATION 7500 // Duration in milliseconds

#define BOARD_LED_ENABLED 1
#define BOARD_LED_TYPE ON_BOARD_LED_MODE_INPUT_TEST

// Home = Down + Start
//#define HOTKEY_01_BUTTONS_MASK 514 // Down + Start
//#define HOTKEY_01_DPAD_MASK 0      // None
//#define HOTKEY_01_ACTION 4        // A1 / Home

#define HOTKEY_00_AUX_MASK 0
#define HOTKEY_00_BUTTONS_MASK 0
#define HOTKEY_00_DPAD_MASK 0
#define HOTKEY_00_ACTION 0

#define HOTKEY_01_AUX_MASK 0
#define HOTKEY_01_BUTTONS_MASK 0
#define HOTKEY_01_DPAD_MASK 0
#define HOTKEY_01_ACTION 0

#define HOTKEY_02_AUX_MASK 0
#define HOTKEY_02_BUTTONS_MASK 0
#define HOTKEY_02_DPAD_MASK 0
#define HOTKEY_02_ACTION 0

#define HOTKEY_03_AUX_MASK 0
#define HOTKEY_03_BUTTONS_MASK 0
#define HOTKEY_03_DPAD_MASK 0
#define HOTKEY_03_ACTION 0

#define HOTKEY_04_AUX_MASK 0
#define HOTKEY_04_BUTTONS_MASK 0
#define HOTKEY_04_DPAD_MASK 0
#define HOTKEY_04_ACTION 0

#define HOTKEY_05_AUX_MASK 0
#define HOTKEY_05_BUTTONS_MASK 0
#define HOTKEY_05_DPAD_MASK 0
#define HOTKEY_05_ACTION 0

#define HOTKEY_06_AUX_MASK 0
#define HOTKEY_06_BUTTONS_MASK 0
#define HOTKEY_06_DPAD_MASK 0
#define HOTKEY_06_ACTION 0

#define HOTKEY_07_AUX_MASK 0
#define HOTKEY_07_BUTTONS_MASK 0
#define HOTKEY_07_DPAD_MASK 0
#define HOTKEY_07_ACTION 0

#define DEFAULT_FORCED_SETUP_MODE FORCED_SETUP_MODE_LOCK_MODE_SWITCH  // Disable switching modes (Xinput, Switch, PS4, etc.)

//#define debounce delay

#endif
